﻿using System;

namespace _1480_running_sum_of_1d_array
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] sum = RunningSum1 (new int[] { 1, 2, 3, 4, 5 });

            for (int i = 0; i < sum.Length; i++)
            {
                Console.Write (sum[i] + " ");
            }
        }

        public static int[] RunningSum(int[] nums)
        {
            int[] sums = new int[nums.Length];
            for (int i = 0; i < nums.Length; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    sums[i] += nums[j];
                }
            }
            return sums;
        }

        public static int[] RunningSum1(int[] nums)
        {
            for (int i = 1; i < nums.Length; i++)
            {
                nums[i] += nums[i - 1];
            }
            return nums;
        }
    }
}
